package me.helllp.dake.generator.engine;

import freemarker.template.TemplateException;
import me.helllp.dake.generator.config.GeneratorEngineConfiguration;
import me.helllp.dake.generator.config.ProjectConfiguration;
import me.helllp.dake.generator.engine.service.ConfigurationGenerator;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

public class GeneratorBuilder {
    public static GeneratorEngineConfiguration loadDefaultEngineConfig() {
        return new GeneratorEngineConfiguration();
    }

    /**
     * 获取项目的代码生成器
     *
     * @param engineConfiguration  引擎配置信息
     * @param projectConfiguration 项目配置信息
     * @return 代码生成器
     */
    public static ProjectGenerator builderProjectGenerator(GeneratorEngineConfiguration engineConfiguration, ProjectConfiguration projectConfiguration) throws TemplateException, IOException, InvocationTargetException, IllegalAccessException {
        ProjectGenerator generator = null;
        switch (projectConfiguration.getProjectType()){
            case COMPONENT:
                generator = new ComponentGenerator(projectConfiguration);
                break;
            case NORMAL_SERVICE:
                generator = new NormalServiceGenerator(projectConfiguration);
                break;
            case MICRO_SERVICE:
                generator = new MicroServiceGenerator(projectConfiguration);
                break;
        }

        if(generator == null) {
            throw new RuntimeException("项目类型不支持");
        }

        // 代码生成器初始化
        generator.initGenerator(engineConfiguration);

        return generator;
    }
}
